﻿using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BitsOfStuff.Support
{
    /// <summary>
    /// Set of function that are used for debuging
    /// </summary>
    public static class DebugFunction
    {
        /// <summary>
        /// Function for show footsteps or vector sequence for debuging
        /// </summary>
        /// <param name="findSequence">Sequence to show</param>
        public static void showDebug(List<int> findSequence)
        {
            string msg = SupportFunctions.convertFromSequenceToString(findSequence);
            MyParameters.debugBox.AppendText(msg + "\n");
            MyParameters.debugText.Text = msg;
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="findSequence"></param>
        public static void showDebug(string findSequence)
        {
            MyParameters.debugBox.AppendText(findSequence + "\n");
            MyParameters.debugText.Text = findSequence;
        }

        /// <summary>
        /// Function for showing text on bottom debug line
        /// </summary>
        /// <param name="st"></param>
        public static void showDebugTopLine(string st)
        {
            MyParameters.debugText.Text = st;
        }

        /// <summary>
        /// Function that show single char to debug
        /// </summary>
        /// <param name="c">Char to show</param>
        public static void addCharToDebug(char c)
        {
            //if (MyParameters.debugBox.Dispatcher.CheckAccess())
            //{
            //    MyParameters.debugBox.AppendText(addCharToDebugSafe(c));
            //}
            //else
            //{
            //    MyParameters.debugBox.Dispatcher.Invoke(
            //        new Action(() => MyParameters.debugBox.AppendText(addCharToDebugSafe(c))));
            //}
        }

        /*
                private static string addCharToDebugSafe(char c)
                {
                    return c.ToString(CultureInfo.InvariantCulture);
                }
        */

        /// <summary>
        /// Function to convert action list to formated string line whit header
        /// </summary>
        /// <param name="header">Header of string</param>
        /// <param name="actions">Actions list to show</param>
        /// <returns>Formated string</returns>
        public static string actionsToString(string header, List<MyActions.MyAction> actions)
        {
            if (actions == null || !actions.Any())
            {
                return "No actions in " + header.ToUpperInvariant();
            }
            var result = new StringBuilder(header + " :");
            foreach (MyActions.MyAction myAction in actions)
            {
                if (myAction is MyActions.MyShowAction)
                {
                    var tmp = myAction as MyActions.MyShowAction;
                    char tmpChar = tmp.getChar();
                    result.AppendFormat(myAction.isFinal() ? ">{0}< ," : "{0} ,", tmpChar);
                }
            }
            return result.ToString();
        }
    }
}